<template>
  <div>
    <tableComponents
      :pagination="{currentPage,pageSize:pagesize,total:life_list.all_num}"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="receive_search"
      :searchData="userSearchData"
      :isHaveExport="false"
      :isHaveAdd="false"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="life_list.data"
          v-loading="loading"
          stripe
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection"></el-table-column>
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户信息" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{scope.row.nickname || '----'}}</span>
                </div>
                <div>
                  <span>用户账号：</span>
                  <span>{{scope.row.username}}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="订单信息" min-width="250">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>充值类型：</span>
                  <span>{{scope.row.types || '----'}}</span>
                </div>
                <div>
                  <span>订单号：</span>
                  <span>{{scope.row.oid || '----'}}</span>
                </div>
                <div>
                  <span>充值帐号：</span>
                  <span>{{scope.row.game_userid}}</span>
                </div>
                <div>
                  <span>创建时间：</span>
                  <span>{{scope.row.created_time |getTimeFormat}}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="金额信息" min-width="250">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>充值面额：</span>
                  <span>{{scope.row.game_money}}</span>
                </div>
                <div>
                  <span>实际支付：</span>
                  <span>{{scope.row.money}}</span>
                </div>
                <div>
                  <span>备注：</span>
                  <span>{{scope.row.reason || '---'}}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单状态" min-width="200">
            <template slot-scope="scope">
              <div v-if="scope.row.is_pay == 0">
                <span>支付状态：</span>
                <el-tag effect="dark" type="danger">未支付</el-tag>
              </div>
              <div v-if="scope.row.is_pay == 1">
                <span>支付状态：</span>
                <el-tag effect="dark">已支付</el-tag>
              </div>
              <div
                v-if="scope.row.is_pay == 1 && scope.row.game_state == 0"
                style="padding-top:10px;"
              >
                <span>是否到账：</span>
                <el-tag effect="dark" type="danger">未到账</el-tag>
              </div>
              <div
                v-if="scope.row.is_pay == 1 && scope.row.game_state == 1"
                style="padding-top:10px;"
              >
                <span>是否到账：</span>
                <el-tag effect="dark">已到账</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="80">
            <template slot-scope="scope">
              <el-button
                type="success"
                size="mini"
                @click="updateStatus(scope.row)"
                v-if="scope.row.is_pay == 1 && scope.row.game_state == 0"
              >
                更新状态
              </el-button>
              <el-button type="danger" size="mini" @click="del_list_detail(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="deleteAll_life">删除</a>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import { platoonIndexSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  name: "coin_must",
  data() {
    return {
      userSearchData: platoonIndexSearchData,
      serarch_from: {},
      label_dis: false,
      edit_form: {
        id: "",
        oid: "",
        status: 0,
        readme: ""
      },
      dioLoading: false,
      dialogeditVisible: false,
      is_search: false,
      loading: false,
      multipleSelection: [],
      life_list: {},
      currentPage: 1, //初始页
      pagesize: 10, //    每页的数据
      formLabelWidth: "120px"
    };
  },

  created() {
    this.get_life_list();
  },
  methods: {
    updateStatus(val) {
      this.$api.getPage.juhe_recharge_recharge({ id: val.id }).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: "更新成功" });
          this.get_life_list(this.serarch_from);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteAll_life() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getPage.del_lifelist({ id_str: str }).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", "您已经删除了这条信息。", "success");
                this.get_life_list();
              } else {
                this.$swal("删除失败！", "出错啦！", "success");
                this.get_life_list();
              }
            });
          }
        });
      }
    },
    del_list_detail(item) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: item.id };
          this.$api.getPage.del_lifelist(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这些信息。", "success");
              this.get_life_list();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
              this.get_life_list();
            }
          });
        }
      });
    },
    receive_search(val) {
      this.serarch_from = val;
      this.get_life_list(val);
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function(size) {
      //每页下拉显示数据
      var params = this.serarch_from;
      params.page = "1";
      params.page_size = size;
      this.pagesize = size;
      this.get_life_list(params);
    },
    handleCurrentChange: function(currentPage) {
                this.currentPage = currentPage;
      var params = this.serarch_from;
      params.page = currentPage;
      params.page_size = this.pagesize;
      this.get_life_list(params);
    },

    get_life_list(data) {
      this.loading = true;
      var params = {};
      params = data || {};
      this.$api.getPage.get_lifelist(params).then(res => {
        if (res.data.code == 200) {
          this.life_list = res.data.result;
          this.loading = false;
        } else {
          this.$fnc.alerterror(res.data.result);
          this.loading = false;
        }
      });
    }
  },
  watch: {}
};
</script>
<style  scoped>
</style>
